package dao;
// default package

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import pojobean.Pros;

/**
 * A data access object (DAO) providing persistence and search support for Pros
 * entities. Transaction control of the save(), update() and delete() operations
 * can directly support Spring container-managed transactions or they can be
 * augmented to handle user-managed Spring transactions. Each of these methods
 * provides additional information for how to configure it for the desired type
 * of transaction control.
 * 
 * @see .Pros
 * @author MyEclipse Persistence Tools
 */

public class ProsDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(ProsDAO.class);
	// property constants
	public static final String PROSHOP = "proshop";
	public static final String PRONAME = "proname";
	public static final String PRICE = "price";
	public static final String DISCOUNT = "discount";
	public static final String FILENAME = "filename";
	public static final String BEI = "bei";
	public static final String EXTBEI = "extbei";
	public static final String STATUS = "status";
	public static final String SAVETIME = "savetime";
	public static final String CJNUM = "cjnum";
	public static final String CC = "cc";

	protected void initDao() {
		// do nothing
	}

	public void save(Pros transientInstance) {
		log.debug("saving Pros instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(Pros persistentInstance) {
		log.debug("deleting Pros instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Pros findById(java.lang.Integer id) {
		log.debug("getting Pros instance with id: " + id);
		try {
			Pros instance = (Pros) getHibernateTemplate().get("Pros", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(Pros instance) {
		log.debug("finding Pros instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Pros instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Pros as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByProshop(Object proshop) {
		return findByProperty(PROSHOP, proshop);
	}

	public List findByProname(Object proname) {
		return findByProperty(PRONAME, proname);
	}

	public List findByPrice(Object price) {
		return findByProperty(PRICE, price);
	}

	public List findByDiscount(Object discount) {
		return findByProperty(DISCOUNT, discount);
	}

	public List findByFilename(Object filename) {
		return findByProperty(FILENAME, filename);
	}

	public List findByBei(Object bei) {
		return findByProperty(BEI, bei);
	}

	public List findByExtbei(Object extbei) {
		return findByProperty(EXTBEI, extbei);
	}

	public List findByStatus(Object status) {
		return findByProperty(STATUS, status);
	}

	public List findBySavetime(Object savetime) {
		return findByProperty(SAVETIME, savetime);
	}

	public List findByCjnum(Object cjnum) {
		return findByProperty(CJNUM, cjnum);
	}

	public List findByCc(Object cc) {
		return findByProperty(CC, cc);
	}

	public List findAll() {
		log.debug("finding all Pros instances");
		try {
			String queryString = "from Pros";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public Pros merge(Pros detachedInstance) {
		log.debug("merging Pros instance");
		try {
			Pros result = (Pros) getHibernateTemplate().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(Pros instance) {
		log.debug("attaching dirty Pros instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Pros instance) {
		log.debug("attaching clean Pros instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static ProsDAO getFromApplicationContext(ApplicationContext ctx) {
		return (ProsDAO) ctx.getBean("ProsDAO");
	}
}